package com.ruoyi.common.exception;

import com.ruoyi.common.exception.base.BaseException;

import java.util.Locale;


public class I18nException extends BaseException {
    private static final long serialVersionUID = 1L;

    private final String messageKey;
    private final Object[] args;
    private Locale locale;

    public I18nException(String messageKey) {
        this("I18", messageKey, null, null);
    }

    public I18nException(String messageKey, String module) {
        this(module, messageKey, null, null);
    }
    public I18nException(String messageKey, Object[] args) {
        this(messageKey, args, null);
    }

    public I18nException(String messageKey, Object[] args, Locale locale) {
        this("I18", messageKey, args, locale);
    }

    public I18nException(String module, String messageKey, Object[] args, Locale locale) {
        super(module, "500", args, null);
        this.messageKey = messageKey;
        this.args = args;
        this.locale = locale;
    }

    public String getMessageKey() {
        return messageKey;
    }

    public Object[] getArgs() {
        return args;
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    @Override
    public String getMessage() {
        // 这里可以返回默认消息，或者留空让全局异常处理器处理
        return "I18nException: " + messageKey;
    }
}
